package com.hinotoyk.testsystem.service;

import com.hinotoyk.testsystem.entity.TestPaperInfo;
import com.hinotoyk.testsystem.entity.TestPaperInfoExample;
import com.hinotoyk.testsystem.mappers.TestPaperInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TestPaperService {
    @Resource
    private TestPaperInfoMapper mapper;

    public boolean AddTestPaper(TestPaperInfo tp){
        return mapper.insert(tp) != 0;
    }

    public boolean DeleteTestPaper(int id){
        return mapper.deleteByPrimaryKey(id) != 0;
    }

    public List<TestPaperInfo> FindTestPaperByTeacherId(int id){
        TestPaperInfoExample e = new TestPaperInfoExample();
        e.createCriteria().andTeacherIdEqualTo(id);
        return mapper.selectByExample(e);
    }

    public TestPaperInfo FindTestPaper(int id){
        return mapper.selectByPrimaryKey(id);
    }

    public List<TestPaperInfo> getAllTestPaperByTeachId(int teacherId){
        TestPaperInfoExample example = new TestPaperInfoExample();
        example.createCriteria().andTeacherIdEqualTo(teacherId);
        List<TestPaperInfo> testPaperInfos = mapper.selectByExample(example);
        return testPaperInfos;
    }

    public List<TestPaperInfo> getAllTestPaper(){
        TestPaperInfoExample example = new TestPaperInfoExample();
        List<TestPaperInfo> testPaperInfos = mapper.selectByExample(example);
        return testPaperInfos;
    }
}
